package com.ymatou.iapi.userservice.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.UnBindMobileRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.req.BindMobileReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.BindMobileCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*绑定邮箱Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BindMobile{
	private static BindMobileReq bindMobileBean;
	private static BindMobileCall bindMobileCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("绑定邮箱Test");
	}

	@Before
	public void caseUp() {
		bindMobileBean=new BindMobileReq();
		bindMobileCall=new BindMobileCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(bindMobileCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BindMobile_001() {
		Logger.start(true,"绑定手机,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMobile(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			bindMobileBean.setMobile(TestDataManager.getPhoneNum());
			bindMobileBean.setUserId(uid);
			bindMobileCall.setData(bindMobileBean);
			bindMobileCall.callService();			
			Logger.verifyEquals("true", bindMobileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", bindMobileCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(bindMobileBean.getMobile(), ui.getLoginMobile(), "验证Mobile");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobile_002() {
		Logger.start(true,"操作幂等,成功");
		//操作幂等 成功
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			bindMobileBean.setMobile(TestDataManager.getPhoneNum());
			bindMobileBean.setUserId(uid);
			bindMobileCall.setData(bindMobileBean);
			bindMobileCall.callService();
			bindMobileCall.callService();
			Logger.verifyEquals("true", bindMobileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", bindMobileCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobile_003() {
		Logger.start(false,"手机已经绑定,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			CreateUserReq cur2 = new CreateUserReq();
			cur2 = JUserCallService.initCreateUserBean(cur2);
			Integer uid2 = JUserCallService.createUserCall(cur2);
			
			bindMobileBean.setMobile(cur2.getMobile());
			bindMobileBean.setUserId(uid);
			bindMobileCall.setData(bindMobileBean);
			bindMobileCall.callService();
			Logger.verifyEquals("false", bindMobileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100005", bindMobileCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("手机号已被使用", bindMobileCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BindMobile_004() {
		Logger.start(true,"解绑后绑定手机,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			UnBindMobileRequestDtoBean ub=new UnBindMobileRequestDtoBean();
			ub.setUserId(uid);
			ub.setMobile(cur.getMobile());
			JUserCallService.UnBindMobileCall(ub);
			bindMobileBean.setMobile(TestDataManager.getPhoneNum());
			bindMobileBean.setUserId(uid);
			bindMobileCall.setData(bindMobileBean);
			bindMobileCall.callService();			
			Logger.verifyEquals("true", bindMobileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", bindMobileCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(bindMobileBean.getMobile(), ui.getLoginMobile(), "验证Mobile");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobile_005() {
		Logger.start(false,"不输入userid,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMobile(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			bindMobileBean.setMobile(TestDataManager.getPhoneNum());
//			bindMobileBean.setUserId(uid);
			bindMobileCall.setData(bindMobileBean);
			bindMobileCall.callService();
			Logger.verifyEquals("false", bindMobileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", bindMobileCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("用户ID未提供", bindMobileCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BindMobile_006() {
		Logger.start(false,"不输入mobile,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMobile(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
//			bindMobileBean.setMobile(TestDataManager.getPhoneNum());
			bindMobileBean.setUserId(uid);
			bindMobileCall.setData(bindMobileBean);
			bindMobileCall.callService();
			Logger.verifyEquals("false", bindMobileCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", bindMobileCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("Mobile 未提供", bindMobileCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}